<?php

/**
 * This is the model class for table "ndk_health_kredit".
 *
 * The followings are the available columns in table 'ndk_health_kredit':
 * @property integer $id
 * @property string $nota_debet_no
 * @property string $endorsement_no
 * @property double $nominal
 * @property string $policy_cost_pm
 * @property double $policy_cost
 * @property double $admin_broker
 * @property string $admin_broker_pm
 * @property double $discount
 * @property string $discount_pm
 * @property integer $discount_percent
 * @property double $adjusment
 * @property string $adjusment_pm
 * @property double $brokerage
 * @property string $brokerage_pm
 * @property integer $brokerage_percent
 * @property integer $ppn
 * @property integer $ppn_percent
 * @property integer $pph
 * @property integer $pph_percent
 * @property string $note
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 * @property integer $installment_ke
 * @property double $stamp_duty
 * @property string $stamp_duty_pm
 * @property double $premium
 * @property string $is_bayar
 * @property double $nett_to_insurance
 * @property double $jml_bayar
 * @property double $diskon_asuransi
 * @property string $diskon_asuransi_pm
 * @property integer $diskon_asuransi_percent
 * @property integer $posting
 * @property integer $reg_health_policy_id
 * @property double $sisa_bayar
 * @property double $kurang_bayar
 * @property double $stampduty_asuransi
 * @property string $stampduty_asuransi_pm
 * @property integer $value_brokerage
 * @property string $type
 */
class NdkHealthKredit extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ndk_health_kredit';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nota_debet_no', 'required'),
			array('discount_percent, brokerage_percent, ppn, ppn_percent, pph, pph_percent, createdby, updatedby, installment_ke, diskon_asuransi_percent, posting, reg_health_policy_id, value_brokerage, client_tahu_diskon', 'numerical', 'integerOnly'=>true),
			array('nominal, policy_cost, admin_broker, discount, adjusment, net_komisi, brokerage, stamp_duty, premium, nett_to_insurance, jml_bayar, diskon_asuransi, sisa_bayar, kurang_bayar, stampduty_asuransi', 'numerical'),
			array('nota_debet_no, endorsement_no', 'length', 'max'=>50),
			array('policy_cost_pm, admin_broker_pm, discount_pm, adjusment_pm, brokerage_pm, stamp_duty_pm, is_bayar, diskon_asuransi_pm, stampduty_asuransi_pm', 'length', 'max'=>1),
			array('note', 'length', 'max'=>100),
			array('type', 'length', 'max'=>5),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, client_tahu_diskon, due_date, net_komisi, nota_debet_no, endorsement_no, nominal, policy_cost_pm, policy_cost, admin_broker, admin_broker_pm, discount, discount_pm, discount_percent, adjusment, adjusment_pm, brokerage, brokerage_pm, brokerage_percent, ppn, ppn_percent, pph, pph_percent, note, createdby, createdtime, updatedby, updatedtime, installment_ke, stamp_duty, stamp_duty_pm, premium, is_bayar, nett_to_insurance, jml_bayar, diskon_asuransi, diskon_asuransi_pm, diskon_asuransi_percent, posting, reg_health_policy_id, sisa_bayar, kurang_bayar, stampduty_asuransi, stampduty_asuransi_pm, value_brokerage, type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nota_debet_no' => 'Nota Debet No',
			'endorsement_no' => 'Endorsement No',
			'nominal' => 'Nominal',
			'policy_cost_pm' => 'Policy Cost Pm',
			'policy_cost' => 'Biaya Polis',
			'admin_broker' => 'Admin Broker',
			'admin_broker_pm' => 'Admin Broker Pm',
			'discount' => 'Diskon Agra',
			'discount_pm' => 'Discount Pm',
			'discount_percent' => 'Discount Percent',
			'adjusment' => 'Adjusment',
			'adjusment_pm' => 'Adjusment Pm',
			'brokerage' => 'Brokerage',
			'brokerage_pm' => 'Brokerage Pm',
			'brokerage_percent' => 'Brokerage Percent',
			'ppn' => 'Ppn',
			'ppn_percent' => 'Ppn Percent',
			'pph' => 'Pph',
			'pph_percent' => 'Pph Percent',
			'note' => 'Note',
			'createdby' => 'Createdby',
			'createdtime' => 'Tanggal Input',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
			'installment_ke' => 'Installment Ke',
			'stamp_duty' => 'Materai Agra',
			'stamp_duty_pm' => 'stamp_duty_pm',
			'premium' => 'Premi',
			'is_bayar' => 'Is Bayar',
			'nett_to_insurance' => 'Nett To Insurance',
			'jml_bayar' => 'Jml Bayar',
			'diskon_asuransi' => 'Diskon Asuransi',
			'diskon_asuransi_pm' => 'Diskon Asuransi Pm',
			'diskon_asuransi_percent' => 'Diskon Asuransi Percent',
			'posting' => 'Posting',
			'reg_health_policy_id' => 'Reg Health Policy',
			'sisa_bayar' => 'Sisa Bayar',
			'kurang_bayar' => 'Kurang Bayar',
			'stampduty_asuransi' => 'Materai Asuransi',
			'stampduty_asuransi_pm' => 'Stampduty Asuransi Pm',
			'value_brokerage' => 'Value Brokerage',
			'type' => 'Tipe',
			'client_tahu_diskon' => 'Client Tahu Diskon Asuransi',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nota_debet_no',$this->nota_debet_no,true);
		$criteria->compare('endorsement_no',$this->endorsement_no,true);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('policy_cost_pm',$this->policy_cost_pm,true);
		$criteria->compare('policy_cost',$this->policy_cost);
		$criteria->compare('admin_broker',$this->admin_broker);
		$criteria->compare('admin_broker_pm',$this->admin_broker_pm,true);
		$criteria->compare('discount',$this->discount);
		$criteria->compare('discount_pm',$this->discount_pm,true);
		$criteria->compare('discount_percent',$this->discount_percent);
		$criteria->compare('adjusment',$this->adjusment);
		$criteria->compare('adjusment_pm',$this->adjusment_pm,true);
		$criteria->compare('brokerage',$this->brokerage);
		$criteria->compare('brokerage_pm',$this->brokerage_pm,true);
		$criteria->compare('brokerage_percent',$this->brokerage_percent);
		$criteria->compare('ppn',$this->ppn);
		$criteria->compare('ppn_percent',$this->ppn_percent);
		$criteria->compare('pph',$this->pph);
		$criteria->compare('pph_percent',$this->pph_percent);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('installment_ke',$this->installment_ke);
		$criteria->compare('stamp_duty',$this->stamp_duty);
		$criteria->compare('stamp_duty_pm',$this->stamp_duty_pm,true);
		$criteria->compare('premium',$this->premium);
		$criteria->compare('is_bayar',$this->is_bayar,true);
		$criteria->compare('nett_to_insurance',$this->nett_to_insurance);
		$criteria->compare('jml_bayar',$this->jml_bayar);
		$criteria->compare('diskon_asuransi',$this->diskon_asuransi);
		$criteria->compare('diskon_asuransi_pm',$this->diskon_asuransi_pm,true);
		$criteria->compare('diskon_asuransi_percent',$this->diskon_asuransi_percent);
		$criteria->compare('posting',$this->posting);
		$criteria->compare('reg_health_policy_id',$this->reg_health_policy_id);
		$criteria->compare('sisa_bayar',$this->sisa_bayar);
		$criteria->compare('kurang_bayar',$this->kurang_bayar);
		$criteria->compare('stampduty_asuransi',$this->stampduty_asuransi);
		$criteria->compare('stampduty_asuransi_pm',$this->stampduty_asuransi_pm,true);
		$criteria->compare('value_brokerage',$this->value_brokerage);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('client_tahu_diskon',$this->client_tahu_diskon,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return NdkHealthKredit the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}


	public function getKlien($reg_policy_id){

		
			$clientId = RegHealthPolicy::model()->findByPk($reg_policy_id)->mst_client_id;
			$clientName = MstClient::model()->findByPk($clientId)->name;
		
		return $clientName;
	}

}
